<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>计数器案例</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .bigbox {
        width: 300px;
        height: 50px;
        margin: 50px auto;
        border-radius: 10px;
        text-align: center;
        display: flex;
        overflow: hidden;
        box-shadow: 2px 2px 10px #909090;
      }
      button {
        width: 95px;
        height: 50px;
        font-size: 40px;
        cursor: pointer;
        border: none;
      }
      span {
        font-size: 40px;
        height: 100%;
        flex: 1;
      }
    </style>
  </head>
  <body>
    <!-- 计数器功能区域 -->
    <div id="app">
      <div class="bigbox">
        <button @click="sub">-</button>
        <span>{{num}}</span>
        <button @click="add">+</button>
      </div>
    </div>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      var app = new Vue({
        el: "#app",
        data: {
          num: 1,
        },
        methods: {
          add: function (num) {
            if (this.num < 10) {
              this.num++;
            } else {
              alert("已经加到最大值，不可再加");
            }
          },
          sub: function (num) {
            if (this.num > 0) {
              this.num--;
            } else {
              alert("已经加减到最小值，不可再减");
            }
          },
        },
      });
    </script>
  </body>
</html>
